//
//  ViewController.m
//  UI05_图片读取
//
//  Created by aaaaaa on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatButton];

}

- (void)creatButton{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.button setImage:image forState:UIControlStateNormal];
    self.button.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:self.button];
    
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAction:(UIButton *)button{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    //是否允许用户编辑
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    
    [self presentViewController:picker animated:YES completion:^{
        
        
    }];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    NSLog(@"%@", info);
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [self.button setImage:image forState:UIControlStateNormal];
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
    
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
